//
//  NSString+FintCommon.h
//  FintechCoreKit
//  Created by FeiTai_Tyg on 2017/12/16.
//  Copyright © 2017年  海德信息. All rights reserved.

#import "NSString+FintCommon.h"
#import <CommonCrypto/CommonDigest.h>
#import "sys/utsname.h"

@implementation NSString (FintCommon)

+ (NSString *)userAgentStr {
    struct utsname systemInfo;
    uname(&systemInfo);
    NSString *deviceString = [NSString stringWithCString:systemInfo.machine encoding:NSUTF8StringEncoding];
    return [NSString stringWithFormat:@"%@/%@ (%@; iOS %@; Scale/%0.2f)", [[[NSBundle mainBundle] infoDictionary] objectForKey:(__bridge NSString *)kCFBundleExecutableKey] ?: [[[NSBundle mainBundle] infoDictionary] objectForKey:(__bridge NSString *)kCFBundleIdentifierKey], (__bridge id)CFBundleGetValueForInfoDictionaryKey(CFBundleGetMainBundle(), kCFBundleVersionKey) ?: [[[NSBundle mainBundle] infoDictionary] objectForKey:(__bridge NSString *)kCFBundleVersionKey], deviceString, [[UIDevice currentDevice] systemVersion], ([[UIScreen mainScreen] respondsToSelector:@selector(scale)] ? [[UIScreen mainScreen] scale] : 1.0f)];
}

-(BOOL)containsEmoji {
    if (!self || self.length <= 0) {
        return NO;
    }
    __block BOOL returnValue = NO;
    [self enumerateSubstringsInRange:NSMakeRange(0, [self length]) options:NSStringEnumerationByComposedCharacterSequences usingBlock:
     ^(NSString *substring, NSRange substringRange, NSRange enclosingRange, BOOL *stop) {
         
         const unichar hs = [substring characterAtIndex:0];
         // surrogate pair
         if (0xd800 <= hs && hs <= 0xdbff) {
             if (substring.length > 1) {
                 const unichar ls = [substring characterAtIndex:1];
                 const int uc = ((hs - 0xd800) * 0x400) + (ls - 0xdc00) + 0x10000;
                 if (0x1d000 <= uc && uc <= 0x1f77f) {
                     returnValue = YES;
                 }
             }
         } else if (substring.length > 1) {
             const unichar ls = [substring characterAtIndex:1];
             if (ls == 0x20e3) {
                 returnValue = YES;
             }
             
         } else {
             // non surrogate
             if (0x2100 <= hs && hs <= 0x27ff) {
                 returnValue = YES;
             } else if (0x2B05 <= hs && hs <= 0x2b07) {
                 returnValue = YES;
             } else if (0x2934 <= hs && hs <= 0x2935) {
                 returnValue = YES;
             } else if (0x3297 <= hs && hs <= 0x3299) {
                 returnValue = YES;
             } else if (hs == 0xa9 || hs == 0xae || hs == 0x303d || hs == 0x3030 || hs == 0x2b55 || hs == 0x2b1c || hs == 0x2b1b || hs == 0x2b50) {
                 returnValue = YES;
             }
         }
     }];
    
    return returnValue;
}
- (NSString *)noEmoji {
    //去除表情规则
    //  \u0020-\\u007E  标点符号，大小写字母，数字
    //  \u00A0-\\u00BE  特殊标点  (¡¢£¤¥¦§¨©ª«¬­®¯°±²³´µ¶·¸¹º»¼½¾)
    //  \u2E80-\\uA4CF  繁简中文,日文，韩文 彝族文字
    //  \uF900-\\uFAFF  部分汉字
    //  \uFE30-\\uFE4F  特殊标点(︴︵︶︷︸︹)
    //  \uFF00-\\uFFEF  日文  (ｵｶｷｸｹｺｻ)
    //  \u2000-\\u201f  特殊字符(‐‑‒–—―‖‗‘’‚‛“”„‟)
    // 注：对照表 http://blog.csdn.net/hherima/article/details/9045765
    
    NSRegularExpression* expression = [NSRegularExpression regularExpressionWithPattern:@"[^\\u0020-\\u007E\\u00A0-\\u00BE\\u2E80-\\uA4CF\\uF900-\\uFAFF\\uFE30-\\uFE4F\\uFF00-\\uFFEF\\u2000-\\u201f\r\n]" options:NSRegularExpressionCaseInsensitive error:nil];
    
    
    NSString* result = [expression stringByReplacingMatchesInString:self options:0 range:NSMakeRange(0, self.length) withTemplate:@""];
    
    return result;
}

#pragma mark emotion_monkey
+ (NSDictionary *)emotion_monkey_dict {
    static NSDictionary *_emotion_monkey_dict;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        _emotion_monkey_dict = @{@"coding_emoji_01": @"哈哈",
                                 @"coding_emoji_02": @"吐",
                                 @"coding_emoji_03": @"压力山大",
                                 @"coding_emoji_04": @"忧伤",
                                 @"coding_emoji_05": @"坏人",
                                 @"coding_emoji_06": @"酷",
                                 @"coding_emoji_07": @"哼",
                                 @"coding_emoji_08": @"你咬我啊",
                                 @"coding_emoji_09": @"内急",
                                 @"coding_emoji_10": @"32个赞",
                                 @"coding_emoji_11": @"加油",
                                 @"coding_emoji_12": @"闭嘴",
                                 @"coding_emoji_13": @"wow",
                                 @"coding_emoji_14": @"泪流成河",
                                 @"coding_emoji_15": @"NO!",
                                 @"coding_emoji_16": @"疑问",
                                 @"coding_emoji_17": @"耶",
                                 @"coding_emoji_18": @"生日快乐",
                                 @"coding_emoji_19": @"求包养",
                                 @"coding_emoji_20": @"吹泡泡",
                                 @"coding_emoji_21": @"睡觉",
                                 @"coding_emoji_22": @"惊讶",
                                 @"coding_emoji_23": @"Hi",
                                 @"coding_emoji_24": @"打发点咯",
                                 @"coding_emoji_25": @"呵呵",
                                 @"coding_emoji_26": @"喷血",
                                 @"coding_emoji_27": @"Bug",
                                 @"coding_emoji_28": @"听音乐",
                                 @"coding_emoji_29": @"垒码",
                                 @"coding_emoji_30": @"我打你哦",
                                 @"coding_emoji_31": @"顶足球",
                                 @"coding_emoji_32": @"放毒气",
                                 @"coding_emoji_33": @"表白",
                                 @"coding_emoji_34": @"抓瓢虫",
                                 @"coding_emoji_35": @"下班",
                                 @"coding_emoji_36": @"冒泡"};
    });
    return _emotion_monkey_dict;
}
- (NSString *)emotionMonkeyName {
    return [NSString emotion_monkey_dict][self];
}

- (NSString *)trimWhitespace {
    NSMutableString *str = [self mutableCopy];
    CFStringTrimWhitespace((__bridge CFMutableStringRef)str);
    return str;
}

- (NSString *)stringByTrimmingLeftCharactersInSet:(NSCharacterSet *)characterSet {
    NSUInteger location = 0;
    NSUInteger length = [self length];
    unichar charBuffer[length];
    [self getCharacters:charBuffer];
    for (location = 0; location < length; location++) {
        if (![characterSet characterIsMember:charBuffer[location]]) {
            break;
        }
    }
    return [self substringWithRange:NSMakeRange(location, length - location)];
}

- (NSString *)stringByTrimmingRightCharactersInSet:(NSCharacterSet *)characterSet {
    NSUInteger location = 0;
    NSUInteger length = [self length];
    unichar charBuffer[length];
    [self getCharacters:charBuffer];
    for (length = [self length]; length > 0; length--) {
        if (![characterSet characterIsMember:charBuffer[length - 1]]) {
            break;
        }
    }
    return [self substringWithRange:NSMakeRange(location, length - location)];
}

//转换拼音
- (NSString *)transformToPinyin {
    if (self.length <= 0) {
        return self;
    }
    NSMutableString *tempString = [NSMutableString stringWithString:self];
    CFStringTransform((CFMutableStringRef)tempString, NULL, kCFStringTransformToLatin, false);
    tempString = (NSMutableString *)[tempString stringByFoldingWithOptions:NSDiacriticInsensitiveSearch locale:[NSLocale currentLocale]];
    return [tempString uppercaseString];
}

//电话号码加*
- (NSString *)telephoneNumberEncryption
{
    NSInteger max = 7;
    NSString *pattern = @"^[1][34578][0-9]{9}$";
    NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",pattern];
    if ([predicate evaluateWithObject:self]) {
        if ([self length] > max) {
            NSString *newStr = [self stringByReplacingCharactersInRange:
                            NSMakeRange(3, 4)  withString:@"****"];
            return newStr;
        }
    }
    return self;
}

+ (BOOL)checkWithPattern:(NSString *)pattern text:(NSString *)text {
    if (!text) {
        return NO;
    }
    NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",pattern];
    return [predicate evaluateWithObject:text];
}

// 去掉手机——86字符
- (NSString *)contactCharacterSetWithCharactersInString {
    NSString *noQianzhui = [self formatPhoneNum:self];
    return [noQianzhui characterSetWithCharactersInString];
}

//字符串 去掉各种字符
- (NSString *)characterSetWithCharactersInString {
    NSMutableString *str1 = [NSMutableString stringWithString:self];
    for (NSInteger i = 0; i < str1.length; i++) {
        unichar c = [str1 characterAtIndex:i];
        NSRange range = NSMakeRange(i, 1);
        //此处可以是任何字符
        if (c == '"' || c == '.' || c == ',' || c == '(' || c == ')' || c == '+' || c == '-' || c == '#' || c == '*' || c == '/' || c == '&' || c == ' ' || c == ' ') {
            [str1 deleteCharactersInRange:range];
            --i;
        }
    }
    NSString *newstr = [NSString stringWithString:str1];
    return newstr;
}

- (NSString *)formatPhoneNum:(NSString *)phone {
    if ([phone hasPrefix:@"86"]) {
        NSString *formatStr = [phone substringWithRange:NSMakeRange(2, [phone length]-2)];
        return formatStr;
    }else if ([phone hasPrefix:@"+86"])
    {
        if ([phone hasPrefix:@"+86·"]||[phone hasPrefix:@"+86 "]) {
            NSString *formatStr = [phone substringWithRange:NSMakeRange(4, [phone length]-4)];
            return formatStr;
        }else if([phone hasPrefix:@"+86  "]||[phone hasPrefix:@"+86··"]){
            NSString *formatStr = [phone substringWithRange:NSMakeRange(5, [phone length]-5)];
            return formatStr;
        }else{
            NSString *formatStr = [phone substringWithRange:NSMakeRange(3, [phone length]-3)];
            return formatStr;
        }
    }
    
    return phone;
    
}

- (CGSize)getSizeWithFont:(UIFont *)font constrainedToSize:(CGSize)size {
    CGSize resultSize = CGSizeZero;
    if (self.length <= 0) {
        return resultSize;
    }
    if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0) {
        NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
        paragraphStyle.lineBreakMode = NSLineBreakByWordWrapping;
        
        NSDictionary * attributes = @{NSFontAttributeName:font,
                                      NSParagraphStyleAttributeName:paragraphStyle};
        
        resultSize = [self boundingRectWithSize:size
                                        options:NSStringDrawingTruncatesLastVisibleLine | NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading
                                     attributes:attributes
                                        context:nil].size;
    } else {
#if __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_7_0
        resultSize = [self sizeWithFont:font constrainedToSize:size lineBreakMode:NSLineBreakByWordWrapping];
        NSMutableAttributedString *attributedStr = [[NSMutableAttributedString alloc] initWithString:self attributes:@{NSFontAttributeName:font}];
        
        NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
        [paragraphStyle setLineSpacing:2.0];
        
        [attributedStr addAttribute:NSParagraphStyleAttributeName
                              value:paragraphStyle
                              range:NSMakeRange(0, [self length])];
        resultSize = [attributedStr boundingRectWithSize:size options:NSStringDrawingUsesLineFragmentOrigin context:nil].size;
        
#endif
        NSDictionary *attribute = @{NSFontAttributeName: font};
        resultSize = [self boundingRectWithSize:size options: NSStringDrawingTruncatesLastVisibleLine | NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading attributes:attribute context:nil].size;
    }
    return resultSize;
    
}

- (CGFloat)getHeightWithFont:(UIFont *)font constrainedToW:(CGFloat)lw {
    return [self getSizeWithFont:font constrainedToSize:(CGSize){lw, MAXFLOAT}].height;
}
- (CGFloat)getWidthWithFont:(UIFont *)font constrainedToH:(CGFloat)lh {
    return [self getSizeWithFont:font constrainedToSize:(CGSize){MAXFLOAT, lh}].width;
}

- (UIColor *)toUIColorByStr {
    
    NSString *cString = [[self stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]] uppercaseString];
    if ([cString hasPrefix:@"#"]) cString = [cString substringFromIndex:1];
    if ([cString length] != 6) return [UIColor blackColor];
    
    // Separate into r, g, b substrings
    NSRange range;
    range.location = 0;
    range.length = 2;
    NSString *rString = [cString substringWithRange:range];
    range.location = 2;
    NSString *gString = [cString substringWithRange:range];
    range.location = 4;
    NSString *bString = [cString substringWithRange:range];
    // Scan values
    unsigned int r, g, b;
    
    [[NSScanner scannerWithString:rString] scanHexInt:&r];
    [[NSScanner scannerWithString:gString] scanHexInt:&g];
    [[NSScanner scannerWithString:bString] scanHexInt:&b];
    
    return [UIColor colorWithRed:((float) r / 255.0f)
                           green:((float) g / 255.0f)
                            blue:((float) b / 255.0f)
                           alpha:1.0f];
}

- (NSString *)charactorGetFirstCharactor:(BOOL)isGetFirst {
    //转成了可变字符串
    NSMutableString *str = [NSMutableString stringWithString:self];
    //先转换为带声调的拼音
    CFStringTransform((CFMutableStringRef)str,NULL, kCFStringTransformMandarinLatin,NO);
    //再转换为不带声调的拼音
    CFStringTransform((CFMutableStringRef)str,NULL, kCFStringTransformMandarinLatin,NO);
    CFStringTransform((CFMutableStringRef)str, NULL, kCFStringTransformStripDiacritics, NO);
    NSString *pinYin = [str capitalizedString];
    //转化为大写拼音
    if(isGetFirst){
        //获取并返回首字母
        return [pinYin substringToIndex:1];
    }else{
        return pinYin;
    }
}

/**
 *  截取URL中的参数
 *
 *  @return NSMutableDictionary parameters
 */
- (NSMutableDictionary *)getURLParameters {
    
    // 查找参数
    NSRange range = [self rangeOfString:@"?"];
    if (range.location == NSNotFound) {
        return nil;
    }
    
    NSMutableDictionary *params = [NSMutableDictionary dictionary];
    
    // 截取参数
    NSString *parametersString = [self substringFromIndex:range.location + 1];
    
    // 判断参数是单个参数还是多个参数
    if ([parametersString containsString:@"&"]) {
        
        // 多个参数，分割参数
        NSArray *urlComponents = [parametersString componentsSeparatedByString:@"&"];
        
        for (NSString *keyValuePair in urlComponents) {
            // 生成Key/Value
            NSArray *pairComponents = [keyValuePair componentsSeparatedByString:@"="];
            NSString *key = [pairComponents.firstObject stringByRemovingPercentEncoding];
            NSString *value = [pairComponents.lastObject stringByRemovingPercentEncoding];
            
            // Key不能为nil
            if (key == nil || value == nil) {
                continue;
            }
            
            id existValue = [params valueForKey:key];
            
            if (existValue != nil) {
                
                // 已存在的值，生成数组
                if ([existValue isKindOfClass:[NSArray class]]) {
                    // 已存在的值生成数组
                    NSMutableArray *items = [NSMutableArray arrayWithArray:existValue];
                    [items addObject:value];
                    
                    [params setValue:items forKey:key];
                } else {
                    
                    // 非数组
                    [params setValue:@[existValue, value] forKey:key];
                }
                
            } else {
                
                // 设置值
                [params setValue:value forKey:key];
            }
        }
    } else {
        // 单个参数
        
        // 生成Key/Value
        NSArray *pairComponents = [parametersString componentsSeparatedByString:@"="];
        
        // 只有一个参数，没有值
        if (pairComponents.count == 1) {
            return nil;
        }
        
        // 分隔值
        NSString *key = [pairComponents.firstObject stringByRemovingPercentEncoding];
        NSString *value = [pairComponents.lastObject stringByRemovingPercentEncoding];
        
        // Key不能为nil
        if (key == nil || value == nil) {
            return nil;
        }
        
        // 设置值
        [params setValue:value forKey:key];
    }
    
    return params;
}

/// 去除所有空格
- (NSString *)removeSpace {
    if (!self) {
        return @"";
    }
    return [self stringByReplacingOccurrencesOfString:@" " withString:@""];
}

+ (BOOL)isBlank:(NSString *)str {
    return str == nil || [str isEmptyOrWhitespace];
}

- (BOOL)isEmptyOrWhitespace {
    // A nil or NULL string is not the same as an empty string
    return 0 == self.length ||
    ![self stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]].length;
}

- (NSString *)convertToJsonData:(NSDictionary *)dict {
    
    NSError *error;
    NSData *jsonData = [NSJSONSerialization dataWithJSONObject:dict options:NSJSONWritingPrettyPrinted error:&error];
    NSString *jsonString;
    if (!jsonData) {
        NSLog(@"%@",error);
    }else{
        jsonString = [[NSString alloc]initWithData:jsonData encoding:NSUTF8StringEncoding];
    }
    NSMutableString *mutStr = [NSMutableString stringWithString:jsonString];
    NSRange range = {0,jsonString.length};
    //去掉字符串中的空格
    [mutStr replaceOccurrencesOfString:@" " withString:@"" options:NSLiteralSearch range:range];
    NSRange range2 = {0,mutStr.length};
    //去掉字符串中的换行符
    [mutStr replaceOccurrencesOfString:@"\n" withString:@"" options:NSLiteralSearch range:range2];
    return mutStr;
    
}

// 判断 字符串 是否全为数字
- (BOOL)checkedNumString {
    NSString *numString = [self stringByTrimmingCharactersInSet:[NSCharacterSet decimalDigitCharacterSet]];
    if(numString.length > 0) {
        return NO;
    }
    return YES;
}

// 银行卡 卡号  4个一组
- (NSString *)bankcardGroupingEncryption:(CGFloat)width {
    // 分组间隔
    NSString *spaceText = @"";
    // 截取后的  字符串
    NSString *tempText = @"";
    
    NSInteger strLength = [self length];
    // 4个一组 **** //
    NSInteger groupCount = 4;
    // 长度
    NSInteger subEndCount = strLength - groupCount;
    // 不是卡
    NSInteger format = 3;
    if (strLength > 16) { format = 4; }
    else if (strLength > 20) { format = 5; }
    else { format = 3; }
    // 循坏  // 一个空格 = 8个字符
    for(NSInteger i = 0; i < width / (format * 8); i++) {
        spaceText = [spaceText stringByAppendingString:@" "];
    }
    if (strLength > groupCount) {
       //  遍历 数组
        for (NSInteger m = 0; m < subEndCount; m++) {
            tempText = [tempText stringByAppendingString:@"*"];
            if ((!((m+1) % groupCount)) && (m)) {
                tempText = [tempText stringByAppendingString:spaceText];
            } else {
                if (m == (subEndCount - 1)) {
                    tempText = [tempText stringByAppendingString:spaceText];
                }
            }
        }
        tempText = [tempText stringByAppendingString:[self substringFromIndex:subEndCount]];
    }
    return tempText;
}

// 电话号码每隔4个字符添加一个空格的字符串算法
- (NSString *)dealPhoneWithString {
    NSString *doneTitle = @"";
    for (NSInteger i = 0; i < self.length; i++) {
        doneTitle = [doneTitle stringByAppendingString:[self substringWithRange:NSMakeRange(i, 1)]];
        if (i == 2) {
            doneTitle = [NSString stringWithFormat:@"%@ ", doneTitle];
        } else if (i == 6) {
            doneTitle = [NSString stringWithFormat:@"%@ ", doneTitle];
        }
    }
    return doneTitle;
}
- (NSString *)nameToPinYin{
    NSMutableString *str = [self mutableCopy];
    CFStringTransform(( CFMutableStringRef)str, NULL, kCFStringTransformMandarinLatin, NO);
    CFStringTransform((CFMutableStringRef)str, NULL, kCFStringTransformStripDiacritics, NO);
    
    return [str stringByReplacingOccurrencesOfString:@" " withString:@""];
}
// 转换成带分隔符的数字  （示例：100000.00 -> 100,000:00）
- (NSString*)toDelimitedNumber {
    CGFloat number = self.floatValue;
    NSNumberFormatter *moneyFormatter = [[NSNumberFormatter alloc] init];
    moneyFormatter.positiveFormat = @"###,##0.00";
    NSString *formatString = [moneyFormatter stringFromNumber:@(number)];
    return formatString;
}

//格式化金钱，用于一些金额计算后不带小数点的情况,格式化后保证有两位小数
- (NSString *)formatterAmountString {
    NSMutableString *mutStr = [[NSMutableString alloc] initWithString:self];
    NSArray *arr = [self componentsSeparatedByString:@"."];
    if (arr.count == 2) {//有小数点
        NSString *numberStr = arr.lastObject;
        if (numberStr.length == 1) {
            [mutStr appendString:@"0"];
        }
    } else if (arr.count == 1 || arr.count == 0){
        [mutStr appendString:@".00"];
    }
    return mutStr;
}
- (NSString *)unicodeString{
    
    NSString *tempStr1 = [self stringByReplacingOccurrencesOfString:@"\\u" withString:@"\\U"];
    
    NSString *tempStr2 = [tempStr1 stringByReplacingOccurrencesOfString:@"\"" withString:@"\\\""];
    
    NSString *tempStr3 = [[@"\"" stringByAppendingString:tempStr2] stringByAppendingString:@"\""];
    
    NSData *tempData = [tempStr3 dataUsingEncoding:NSUTF8StringEncoding];
    
    
    NSPropertyListFormat format = NSPropertyListOpenStepFormat;
    
    NSString *returnStr = [NSPropertyListSerialization propertyListWithData:tempData options:NSPropertyListImmutable format:&format error:nil];
    
    return [returnStr stringByReplacingOccurrencesOfString:@"\\r\\n" withString:@"\n"];
}

-(NSString*)securityCardNoString{
    if(self.length <4){
        return self;
    }
    NSString *sufString = [self substringFromIndex:self.length - 4];
     NSString *fromString = [self substringToIndex:4];
    NSString *securityIdNumString = [NSString stringWithFormat:@"%@  ****  ****  %@", fromString,sufString];
    return securityIdNumString;
}
-(NSString*)securityIphoneNumString{
    if(self.length <4){
        return self;
    }
    NSString *sufString = [self substringFromIndex:self.length - 4];
     NSString *fromString = [self substringToIndex:3];
    NSString *securityIdNumString = [NSString stringWithFormat:@"%@****%@", fromString,sufString];
    return securityIdNumString;
}
-(NSString*)securityIdentityNumString {
    if(self.length <4){
        return self;
    }
    NSString *sufString = [self substringFromIndex:self.length - 4];
     NSString *fromString = [self substringToIndex:3];
    NSString *securityIdNumString = [NSString stringWithFormat:@"%@***********%@", fromString,sufString];
    return securityIdNumString;
}

-(NSString*)lastBankNoFourStr{
    if(self.length <4){
        return self;
    }
    NSString *sufString = [self substringFromIndex:self.length - 4];
    return sufString;
}

- (NSInteger)yuanChangeToFen
{
    if (self.length==0) {
        return 0;
    }
    NSString* wkself = [NSString stringWithFormat:@"%@",self];
    
    NSString* yuanStr = nil;
    NSString* fenStr  = nil;
    
    NSArray *ary = [wkself componentsSeparatedByString:@"."];
    if (ary.count>=1) {
        yuanStr = [ary objectAtIndex:0];
    }
    if (ary.count>=2) {
        fenStr = [ary objectAtIndex:1];
        if (fenStr.length>2) {
            fenStr = [fenStr substringToIndex:2];
        }
    }
    
    NSInteger yuan = [yuanStr integerValue];
    NSInteger fen = 0;
    if (fenStr.length==1) {
        fen = [fenStr integerValue]*10;
    }
    else {
        fen = [fenStr integerValue];
    }
    
    return yuan*100+fen;
}
//-(NSString*)fenChangeToYuan{
//    return _sfmt(@"%ld.%02ld",self.integerValue/100,self.integerValue %100);
//}
//-(NSString*)timeSeparate{
//    NSArray *arr = [self componentsSeparatedByString:@" "];
//    if(arr.count==2){
//        NSString *strtime = arr[1];
//       NSArray *arrtime = [strtime componentsSeparatedByString:@":"];
//        if(arrtime.count >=2){
//            return _sfmt(@"%@:%@",arrtime[0],arrtime[1]);;
//        }
//        return strtime;
//    }
//    return self;
//}
-(NSString*)securityphoneNoString{
    if(self.length <4){
        return self;
    }
    NSString *sufString = [self substringFromIndex:self.length - 4];
    NSString *fromString = [self substringToIndex:3];
    NSString *securityIdNumString = [NSString stringWithFormat:@"%@****%@", fromString,sufString];
    return securityIdNumString;
}
@end
